package com.xncoding.pos.config;

import cn.hutool.core.util.IdUtil;
import com.xncoding.pos.model.Person;
import com.xncoding.pos.service.MessageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.annotation.Resource;

/**
 * 通过环境参数,使用不同的bean
 *
 * @author xx on 2019/10/25
 */
@Configuration
public class MyConfig {

    @Resource
    MessageService messageService;

    @Value("${myservice.config.name}")
    private String name;


    @Value("${myservice.config.devName}")
    private String devName;

//    除了spring.profiles.active来激活一个或者多个profile之外，还可以用spring.profiles.include来叠加profile
//    spring.profiles: testdb
//    spring.profiles.include: proddb,prodmq

    @Bean
    @Profile("dev")
    public Person person1() {
        Person person=new Person();
        person.setId(IdUtil.simpleUUID());
        person.setAge(20);
        person.setName("dev环境");
        return person;
    }

    @Bean
    @Profile("!dev")
    public Person person2() {
        Person person=new Person();
        person.setId(IdUtil.simpleUUID());
        person.setAge(25);
        person.setName("不是dev环境");
        return person;
    }

}
